// @ts-ignore
/* eslint-disable */
import { notLoginResHandler, paramsSerializer, showLoginModal } from '@/utils';
import { request } from '@umijs/max';
// 单个图片上传
export function upLoadImage(params: COMMON.UpLoadImage): Promise<COMMON.BaseSuccess<string>> {
  return request(`/api/portal/image/articleImage`, {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: params,
  });
}
// 多个图片上传
export function upLoadImages(params: COMMON.UpLoadImages): Promise<COMMON.BaseSuccess> {
  return request(`/api/portal/image/articleImages`, {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: params,
  });
}

// 获取文章列表(广场全部可见的)
export async function getArticleList(
  params: ARTICLEAPI.ArticleView,
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ARTICLE>> {
  return request('/api/portal/article/findArticleList', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 文章搜索栏关联词
export async function findArticleByAearchAssociatedWord(
  params: COMMON.ListCommon & {
    articleTitle: ARTICLEAPI.ARTICLE['articleTitle'];
  },
): Promise<COMMON.QueryList<ARTICLEAPI.ARTICLE>> {
  return request('/api/portal/article/findArticleByAearchAssociatedWord', {
    method: 'POST',
    params,
    paramsSerializer,
  });
}

// 获取自己的文章列表
export async function getOneselfArticleList(
  params: ARTICLEAPI.ArticleView,
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ARTICLE>> {
  return request('/api/portal/article/findOwnArticleList', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}
// 删除自己的文章
export async function deleteArticleApi(
  params: ARTICLEAPI.DeleteArticle,
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ARTICLE>> {
  return request('/api/portal/article/deleteArticle', {
    method: 'POST',
    data: params,
    ...(options || {}),
  });
}
// 根据id获取文章内容
export async function getArticleById(
  id: string | number,
): Promise<COMMON.BaseSuccess<ARTICLEAPI.ARTICLE>> {
  return request('/api/portal/article/findArticleById', {
    method: 'GET',
    params: { articleId: id },
  });
}

// 获取公有标签列表
export async function getLabel(
  params: COMMON.ArticleLabelList = { pageSize: 10, current: 1 },
  options?: Record<string, any>,
): Promise<COMMON.BaseSuccess<ARTICLEAPI.ArticleLabe[]>> {
  return request('/api/portal/article-label/findPublicArticleLabel', {
    method: 'POST',
    ...(options || {}),
  });
}

// 发布文章
export async function publishArticle(
  params: ARTICLEAPI.AublishArticle,
): Promise<COMMON.BaseSuccess<any>> {
  return request('/api/portal/article/createArticle', {
    method: 'POST',
    data: params,
  });
}

// 编辑文章
export async function editArticleApi(
  params: ARTICLEAPI.AublishArticle,
): Promise<COMMON.BaseSuccess<any>> {
  return request('/api/portal/article/amendArticle', {
    method: 'POST',
    data: params,
  });
}
// 获取私有标签列表
export async function getPrivateLabel(
  params: COMMON.ArticleLabelList = { pageSize: 10, current: 1 },
  options?: Record<string, any>,
): Promise<COMMON.BaseSuccess<ARTICLEAPI.ArticleLabe[]>> {
  return request('/api/portal/article-label/findPrivateArticleLabel', {
    method: 'POST',
    ...(options || {}),
  });
}

export async function praise(
  params: {
    articleId: string;
    state: number;
  },
  options?: Record<string, any>,
): Promise<COMMON.BaseSuccess<any>> {
  return request('/api/portal/article-like-record/updateArticleLikeState', {
    method: 'POST',
    params,
    paramsSerializer,
    ...(options || {}),
  });
}

// 改变收藏状态
export async function collectArticle(
  data: ARTICLEAPI.UpdateArticleCollectStateT,
): Promise<COMMON.BaseSuccess<any>> {
  return request('/api/portal/article-collect-record/updateArticleCollectState', {
    method: 'POST',
    data,
  });
}

// 获取文章热门标签
export async function getHotArticleLabelList(
  param?: COMMON.ListCommon,
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ArticleLabe & { isActivate?: boolean }>> {
  return request('/api/portal/article-label/findArticleLabel', {
    method: 'POST',
    params: param,
    paramsSerializer,
    ...(options || {}),
  });
}

// 根据文章获取标签
export async function findArticleListByLabel(
  param?: COMMON.ListCommon & { articleLabelId: number },
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ARTICLE & { isActivate?: boolean }>> {
  return request('/api/portal/article/findArticleListByLabel', {
    method: 'GET',
    params: param,
    ...(options || {}),
  });
}
// es关键词搜索文章
export async function findArticleListByTitleEs(
  param?: COMMON.ListCommon & { articleTitle: string | number; more?: boolean },
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.EsArticle & { isActivate?: boolean }>> {
  return request('/api/portal/article/findArticleListByTitleEs', {
    method: 'GET',
    params: param,
    ...(options || {}),
  });
}

// 查看历史记录
export async function findArticleListByLookRecord(
  params?: COMMON.ListCommon & COMMON.DateTimeRangeServiceT,
  options?: Record<string, any>,
): Promise<
  COMMON.QueryList<
    ARTICLEAPI.ARTICLE & {
      articleLikeRecord: ARTICLEAPI.ArticleLikeRecord;
    }
  >
> {
  return showLoginModal(
    request('/api/portal/article/findArticleListByLookRecord', {
      method: 'GET',
      params,
      ...(options || {}),
    }),
  );
}

// 已点赞文章
export async function findArticleListByLikeRecord(
  params: COMMON.ListCommon & COMMON.DateTimeRangeServiceT,
  options?: Record<string, any>,
): Promise<
  COMMON.QueryList<
    ARTICLEAPI.ARTICLE & {
      articleLikeRecord: ARTICLEAPI.ArticleLikeRecord;
    }
  >
> {
  return request('/api/portal/article/findArticleListByLikeRecord', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}
// 已收藏文章
export async function findArticleListByCollectRecord(
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ARTICLE & { isActivate?: boolean }>> {
  return request('/api/portal/article/findArticleListByCollectRecord', {
    method: 'GET',
    ...(options || {}),
  });
}

// 添加评论
export async function createComment(
  data?: ARTICLEAPI.CreateCommentT,
  options?: Record<string, any>,
): Promise<COMMON.BaseSuccess<string>> {
  return request('/api/portal/comment/createComment', {
    method: 'POST',
    data: data,
    ...(options || {}),
  });
}

// 查询评论列表
export async function findArticleCommentListByArticleId(
  params: COMMON.ListCommon & { articleId: string },
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.Comment>> {
  return request('/api/portal/comment/findArticleCommentListByArticleId', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 添加回复
export async function createCommentReply(
  data?: ARTICLEAPI.CreateReplyT,
  options?: Record<string, any>,
): Promise<COMMON.BaseSuccess<string>> {
  return request('/api/portal/comment-reply/createCommentReply', {
    method: 'POST',
    data: data,
    ...(options || {}),
  });
}

//  查询评论回复
export async function findCommentReplyByComment(
  params?: COMMON.ListCommon & ARTICLEAPI.CommentReplyT,
  options?: Record<string, any>,
): Promise<COMMON.QueryList<ARTICLEAPI.ReplyT>> {
  return request('/api/portal/comment-reply/findCommentReplyByComment', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 根据收藏夹信息获取收藏夹内容
export async function findArticleCollectRecord(
  params?: COMMON.ListCommon & ARTICLEAPI.CollectRecordFileQT,
  options?: Record<string, any>,
): Promise<COMMON.QueryList<FAVORITES.FavoritesQT>> {
  return request('/api/portal/article-collect-record/findArticleCollectRecord', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 修改收藏夹内容
export async function updatefavoritesInfo(
  data: ARTICLEAPI.UpdateFavoriteInfo,
  options?: Record<string, any>,
): Promise<COMMON.BaseSuccess> {
  return request('/api/portal/article-collect-record-file/updateArticleCollectRecordFile', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}
// 移动文章到指定收藏夹
export async function updateArticleToFavoriteById(
  data: ARTICLEAPI.UpdateArticleToFavoriteByIdT,
): Promise<COMMON.BaseSuccess> {
  return request('/api/portal/article-collect-record/updateArticleCollectByArticle', {
    method: 'POST',
    data,
  });
}
// 删除收藏夹一并删除文章
export async function deleteArticleCollectRecordFile(
  articleCollectRecordFileId: ARTICLEAPI.ArticleCollectT['articleCollectRecordFileId'],
): Promise<COMMON.BaseSuccess> {
  return request('/api/portal/article-collect-record-file/deleteArticleCollectRecordFile', {
    method: 'DELETE',
    params: { articleCollectRecordFileId },
    paramsSerializer,
  });
}
// 评论点赞或者回复
export async function commentLick(data: ARTICLEAPI.CommentLickT): Promise<COMMON.BaseSuccess> {
  return request(
    '/api/portal/article-comment-reply-like-record/updateArticleCommentLikeRecordState',
    {
      method: 'POST',
      data,
    },
  );
}

// 获取搜索历史
export async function findSearchRecord(): Promise<COMMON.QueryList<ARTICLEAPI.SearchHistoryT>> {
  return notLoginResHandler(() =>
    request('/api/portal/article-search-record/findSearchRecord', {
      method: 'GET',
    }),
  );
}

// 清空搜索历史
export async function deleteArticleSearchRecord(): Promise<COMMON.BaseSuccess> {
  return notLoginResHandler(() =>
    request('/api/portal/article-search-record/deleteArticleSearchRecord', {
      method: 'DELETE',
    }),
  );
}
